{extend name="public/base"/} {block name="body"}
<link rel="stylesheet" type="text/css" href="__PUBLIC__/xsd/css/checkout.css" />
<style>
.addresscard-del {
    -ms-flex-preferred-size: 1.306667rem;
    flex-basis: 1.306667rem;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: end;
    -ms-flex-pack: end;
    justify-content: flex-end;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
}
</style>
<header class="mui-bar mui-bar-nav" style="z-index:7">
    <a class=" mui-icon mui-icon-left-nav mui-pull-left" href="{:url('index/cart/qiye', ['cid'=>$cid ])}"></a>
    <h1 class="mui-title">选择用户</h1>
</header>
<div class="mui-content ">
    {volist name="list" id="vo"}
    <div class="addresscard">
        {eq name="$vo['defaults']" value='1'}
        <div class="addresscard-select"><img src="__PUBLIC__/xsd/img/gg.png"></div>{/eq}
        <div class="addresscard-body " data-addressid="{$vo.id}" {eq name="$vo['defaults']" value='1'}data-noc="1"{/eq}>
            <p class="addresscard-title"> <span class="username">{$vo.username}</span>  <span class="tpl">{$vo.phone}</span> </p>
        </div>
        <a class="addresscard-edit" href="{:url('index/address/addqiye', ['id'=>$vo['id'], 'cid'=>$cid])}"> <span class="mui-icon mui-icon-compose"></span></a>
        <a class="addresscard-del" href="javascript:;" data-id="{$vo['id']}"> <span class="mui-icon mui-icon-trash"></span> </a>
    </div>
    {/volist}
    <div class="addressview-bottom">
        <div class="bottom-text" id="add"><span class="mui-icon mui-icon-plus-filled"></span> 新增收货地址</div>
    </div>
</div>
{/block}
{block name="script"}
  <script type="text/javascript">
    $(function(){
      $('#add').on('click',function(){
        window.location.href = "{:url('index/address/addqiye', ['cid'=>$cid ])}"
      })

      $('.addresscard-body').click(function(){
        var $this = $(this),id = $this.attr('data-addressid'),noc = $this.attr('data-noc');
        if(noc == 1){return ;}

        $.post("{:url('index/address/setqiyeDefaults')}", {
            "id": id,
            'cid': "{$cid}"
        }, function(data) {
            mui.toast('设为默认成功！')
            setTimeout(function() {
                //mui.back()
               window.location.href="{:url('index/cart/qiye', ['cid'=>$cid ])}"
            }, 2000);

        }, "json");
      })

      $('.addresscard-del').on('click', function(){
        var id = $(this).attr('data-id')
        var btnArray = ['否', '是'];
        mui.confirm('您确定要删除用户信息吗？', '删除地址', btnArray, function(e) {
          if (e.index == 1) {
              $.post("{:url('index/address/delqiye')}", {
                  "id": id
              }, function(data) {
                  mui.toast('删除成功！')
                  setTimeout(function() {
                    location.reload()
                  }, 2000);
              }, "json");

          } else {
            return ;
          }
        })
      })
    })
  </script>
{/block}
